var interval = null //倒计时函数
Page({
    data: {
      date: '请选择日期',
      fun_id: 2,
      time: '获取验证码', //倒计时 
      currentTime: 60
    },
    onLoad: function () {
        // body...
    },
    // 获取验证码倒计时
    getCode: function (options) {
      var that = this;
      var currentTime = that.data.currentTime
      interval = setInterval(function () {
        currentTime--;
        that.setData({
          time: currentTime + '秒后重新发送'
        })
        if (currentTime <= 0) {
          clearInterval(interval)
          that.setData({
            time: '重新发送',
            currentTime: 60,
            disabled: false
          })
        }
      }, 1000)
    },
    getVerificationCode() {
      this.getCode();
      var that = this
      that.setData({
        disabled: true
      })
    },
    // 获取验证码倒计时结束
    formBindsubmit: function (e) {
      var name = e.detail.value.userName;
      var ident = e.detail.value.userIdent;
      var phone = e.detail.value.userPhone;
      var code = e.detail.value.userCode;

      if (name.length == 0) {
        wx.showToast({
          title: '请输入姓名！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      if (ident.length == 0) {
        wx.showToast({
          title: '请输入身份证号！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      if (phone.length == 0) {
        wx.showToast({
          title: '请输入手机号！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      if (phone.length != 11) {
        wx.showToast({
          title: '手机号长度有误！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
      if (!myreg.test(phone)) {
        wx.showToast({
          title: '手机号有误！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      if (code.length == 0) {
        wx.showToast({
          title: '请输入验证码！',
          icon: 'success',
          duration: 1500
        })
        return false;
      }
      return true;
      // wx.request({
      //   url: jumpurl + 'my/tixian_zhanghu_add',
      //   data: {
      //     openid: openid,
      //     judge: judge,
      //     phone: phone,
      //     name: name,
      //     zhifu: zhifu,
      //   },
      //   method: "POST",
      //   header: {
      //     "Content-Type": "application/x-www-form-urlencoded" //post
      //   },
      //   success: function (res) {
      //     if (res.data == 1) {
      //       wx.showToast({ 
      //         title: '操作成功',
      //         icon: 'success',
      //         duration: 2000,
      //         success: function () {
      //           setTimeout(function () {
      //             //要延时执行的代码
      //             wx.redirectTo({
      //               url: '/pages/addconunt/addconunt',
      //             })
      //           }, 2000) //延迟时间 
      //         }
      //       })
      //     }
      //   }
      // })

    },

});